<template>
  <div class="contain-body hdda-box">
    <Title></Title>
    <div class="search-contain-body">
      <el-form ref="form"
               inline
               :model="form"
               label-width="75px">
        <el-form-item>
          <div class="d-ib font-table"
               slot="label">设备名称：</div>
          <el-input v-model="form.sbmcs"></el-input>
        </el-form-item>

        <el-form-item>
          <div class="d-ib font-table"
               slot="label">厂商名称：</div>
          <el-input v-model="form.csmcs"></el-input>
        </el-form-item>

        <el-form-item>
          <el-button icon="el-icon-search"
                     class="button-search"
                     @click="onSubmit">搜索</el-button>
        </el-form-item>
      </el-form>

    </div>
    <div>
      <div class="pos-r">
        <Title msg="信息列表"></Title>
        <div class="pos-a" style="right: 0">
          <el-button @click="openOptions('','add')" type="primary" icon="el-icon-plus">
            新增
          </el-button>
        </div>
      </div>
      <CustomTable :columns="columns"
                   :table-data="tableData"
                   :pagination="pagination"
                   @pagination="paginationChange"
                   :total="total">
        <div slot="options"
             slot-scope="scope">
          <el-button @click="openOptions(scope,'details')" style="margin-left: 4px;" class="button-blur">详情</el-button>
          <el-button @click="openOptions(scope,'edit')" style="margin-left: 4px;" class="button-green">编辑</el-button>
          <el-button @click="deleteDate(scope)" style="margin-left: 4px;" class="button-red">删除</el-button>
        </div>
      </CustomTable>
    </div>

    <el-dialog width="819px"
               center
               class="custom-dialog-fill font-table"
               title="活动审批"
               :visible.sync="dialog.open">

      <div class="dialog-title"
           slot="title">
        {{ dialog.title }}
      </div>

      <div class="d-f jc-c">

        <el-form :disabled="flag" class="font-table" style="color: #000000;"ref="form" :model="form" label-width="75px">
          <div class="mb-14"><b>基本信息</b> </div>
          <el-form-item>
            <div class="d-ib font-table" slot="label">地球经度：</div>
            <el-input v-model="form.dqjd" style="width: 180px"></el-input>
            <div class="d-ib font-table"style="margin-left: 40px">地球纬度：</div>
            <el-input v-model="form.dqwd" style="width: 180px"></el-input>
          </el-form-item>
          <el-form-item>
            <div class="d-ib font-table" slot="label">IP 地址：</div>
            <el-input v-model="form.ipdz" style="width: 180px"></el-input>
            <div class="d-ib font-table"style="margin-left: 34px">IPV6 地址：</div>
            <el-input v-model="form.ipv6dz" style="width: 180px"></el-input>
          </el-form-item>

          <el-form-item>
            <div class="d-ib font-table" slot="label">设备名称：</div>
            <el-input v-model="form.sbmc" style="width: 180px"></el-input>
            <div class="d-ib font-table" style="margin-left: 40px">厂商名称：</div>
            <el-input v-model="form.csmc"style="width: 180px"></el-input>
          </el-form-item>


          <el-form-item>
            <div class="d-ib font-table" slot="label">组织机构：</div>
            <el-input v-model="form.gxdwZzjgdm" style="width: 180px"></el-input>
            <div class="d-ib font-table" style="margin-left: 40px">设备类型：</div>
            <el-input v-model="form.sblx"style="width: 180px"></el-input>
          </el-form-item>

          <el-form-item>
            <div class="d-ib font-table"slot="" style="margin-left: -19%">采集数据类型：</div>
            <el-input v-model="form.cjsjlx" style="width: 180px"></el-input>
            <div class="d-ib font-table" style="margin-left: 40px">监视方向：</div>
            <el-input v-model="form.jsfx"style="width: 180px"></el-input>
          </el-form-item>

          <el-form-item>
            <div class="d-ib font-table"slot="" style="margin-left: -22%">摄像机位置类型：</div>
            <el-input v-model="form.sxjwzlx" style="width: 180px"></el-input>
            <div class="d-ib font-table" style="margin-left: 28px">摄像机用途：</div>
            <el-input v-model="form.sxjyt" style="width: 180px"></el-input>
          </el-form-item>

          <el-form-item>
            <div class="d-ib font-table"slot="" style="margin-left: -19%">监视区域说明：</div>
            <el-input type="textarea" v-model="form.jsqysm" style="width: 92.5%"></el-input>
          </el-form-item>

          <div class="mb-14"><b>安装地点</b> </div>
          <el-form-item>
            <div class="d-ib font-table" slot="" style="margin-left: -19%">行政区划代码：</div>
            <el-input v-model="form.azddXzqhdm" style="width: 180px"></el-input>
            <div class="d-ib font-table" style="margin-left: 40px">地址名称：</div>
            <el-input v-model="form.azddDzmc"style="width: 180px"></el-input>
          </el-form-item>
        </el-form>


      </div>
      <div class="d-f jc-c">
        <div v-if="dialog.type=='details'">
          <el-button
                  class="button-cancel"
                  @click="dialog.open = false">关 闭
          </el-button>
        </div>
        <div v-if="dialog.type=='add'">
          <el-button
                  class="button-cancel"
                  @click="cancel()">取 消
          </el-button>
          <el-button
                  class="button-submit mr58"
                  @click="add()">确 定
          </el-button>
        </div>
        <div v-if="dialog.type=='edit'">
          <el-button
                  class="button-cancel"
                  @click="cancel()">取 消
          </el-button>
          <el-button
                  class="button-submit mr58"
                  @click="edit()">确 定
          </el-button>
        </div>
      </div>
    </el-dialog>

  </div>
</template>

<script>
    import Title from "../../../components/Title";
    import CustomTable from "../../../components/CustomTable";

    export default {
        name: "chry",
        components: { Title, CustomTable },
        data () {
            return {
                fileList: [],
                total: 0,
                pagination: {},

                dialog: {
                    title: '新增方案',
                    open: false,
                    type: 'add',//'edit','add','details'
                },
                form: {
                    xm: ''
                },
                tableData: [

                ],
                columns: [

                    {
                        key: 'sbmc',
                        label: '设备名称'
                    },
                    {
                        key: 'csmc',
                        label: '厂商名称'
                    },
                    {
                        key: 'ipdz',
                        label: 'IP 地址'
                    },
                    {
                        key: 'ipv6dz',
                        label: 'IPV6 地址'
                    },

                    {
                        key: 'dqjd',
                        label: '地球经度'
                    },
                    {
                        key: 'dqwd',
                        label: '地球纬度'
                    },
                    {
                        key: 'azddDzmc',
                        label: '安装地点'
                    },
                    {
                        key: 'sxjyt',
                        label: '摄像机用途'
                    },
                    {
                        key: 'options',
                        label: '操作',
                        width: '240px',
                        slot: true
                    }
                ],
            }
        },
        mounted () {
        },
        methods: {
            paginationChange (e) {
                this.pagination = e;
                this.getList(this.pagination.pageNum, this.pagination.pageSize);
            },
            getList (page, limit) {
                this.axios.post('/dxhd-spsb/selectPage', {
                    current: page,
                    size: limit,
                    entity: {
                        sbmc: this.form.sbmcs || '',
                        csmc: this.form.csmcs || ''
                    }

                }).then((res) => {
                    //列表
                    this.tableData = res.data.records;
                this.total = res.data.total;
            }).catch((error) => {
                    console.log(error);
            });
            },
            onSubmit () {
                this.getList(this.pagination.pageNum, this.pagination.pageSize);
            },
            openOptions (scope,params) {
                console.info(scope);
                this.dialog.type = params
                if (params == 'add') {
                    this.flag=false;
                    this.dialog.title = '新增'
                    this.form={}
                }
                if (params == 'edit') {
                    this.flag=false;
                    this.dialog.title = '编辑'
                    this.form=scope.data;
                }
                if (params == 'details') {
                    this.flag=true;
                    this.dialog.title = '详情'
                    this.form=scope.data;
                }
                this.dialog.open = true
            },


            //根据id删除
            getDetail(id) {
                this.axios.post('/dxhd-spsb/removeById', {
                    spsbbm: id || 4588988
                }).then((res) => {
                    this.$message({
                    type: 'success',
                    message: '删除成功!'
                });
            this.onSubmit();
            }).catch((error) => {
                    this.$message({
                    type: 'info',
                    message: '删除失败'
                });
            });
            },

            add(){
                this.axios.post('/dxhd-spsb/save', this.form).then((res) => {
                    this.$message({
                    type: 'success',
                    message: '保存成功!'
                });
                this.dialog.open = false
                this.onSubmit();
            }).catch((error) => {
                    this.$message({
                    type: 'info',
                    message: '保存失败'
                });
            });
            },

            edit(){
                this.axios.post('/dxhd-spsb/updateById', this.form).then((res) => {
                    this.$message({
                    type: 'success',
                    message: '保存成功!'
                });
                this.dialog.open = false

            }).catch((error) => {
                    this.$message({
                    type: 'info',
                    message: '保存失败'
                });
            });
            },

            deleteDate(row) {
                this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '关闭',
                    type: ''
                }).then(() => {
                    this.getDetail(row.data.spsbbm);
            }).catch(() => {
                    this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
            },
            cancel(){
                this.onSubmit();
                this.dialog.open = false;

            }


        }
    }
</script>

<style lang="scss">
  .hdda-box {
    .mb-14 {
      margin-bottom: 14px;
    }

    .mr111 {
      margin-right: 111px;
    }

    .mr58 {
      margin-right: 58px;
    }
    .input {
      width: 205px !important;
    }
  }
</style>



